package com.keffect.effects.animatedEffects;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import com.keffect.effects.AnimatedEffect;

/**
 
 * 
 * @author Matias Varela
 *         <p>
 *         Student of Licenciatura en Ciencias de la Computacion, at the
 *         Universidad Nacional del Sur (Argentina).
 *         <p>
 *         project site: http://code.google.com/p/keffect-project/
 * 
 */
public class SplitVertical extends AnimatedEffect {

	private Rectangle r1, r2;
	private boolean isInit;
	private Color color;


	public SplitVertical(long duration) {
		super(duration);
		isInit = false;
		this.color = Color.black;
	}


	public SplitVertical(long duration, Color color) {
		super(duration);
		isInit = false;
		this.color = color;

	}


	@Override
	public void initEffectProperties() {
		if (!isInit) {
			this.setFrames((long) getEffectPanel().getWidth() / 2);
			r1 = new Rectangle(0, 0, getEffectPanel().getWidth() / 2, getEffectPanel().getHeight());
			r2 = new Rectangle(getEffectPanel().getWidth() / 2, 0, getEffectPanel().getWidth() / 2, getEffectPanel().getHeight());

			isInit = true;
		}
		r1.setLocation(-1, 0);
		r2.setLocation((int) r2.getWidth(), 0);
	}


	@Override
	public boolean isRunning() {
		return (r1.getX() + r1.getWidth()) > 0;
	}


	@Override
	public void run() {
		r1.translate(-1, 0);
		r2.translate(1, 0);
	}


	@Override
	public void doPaintBefore(Graphics2D g) {
	}


	@Override
	public void doPaintAfter(Graphics2D g) {
		Color defaultColor = g.getColor();
		g.setColor(color);
		g.fill(r1);
		g.fill(r2);
		g.setColor(defaultColor);
	}
}
